package demo1;

//牛客网:小红的ABC
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int ret = Integer.MAX_VALUE;
        int n = s.length();
        for(int i = 0; i<n; i++) {
            //长度为奇数
            int l = i, r = i;
            while(l-1>=0 && r+1<n && s.charAt(l-1) == s.charAt(r+1)) {
                l--;
                r++;
                if(r-l+1 > 1) {
                    ret = Math.min(ret, r-l+1);
                }
            }
            
            //长度为偶数
            l = i;
            r = i+1;
            while(l>=0 && r<n && s.charAt(l) == s.charAt(r)) {
                l--;
                r++;
                if(r-l+1 > 1) {
                    ret = Math.min(ret, r-l-1);
                    break;
                }
            }

            if(ret == 2) {
                break;
            }
        }

        ret = ret == Integer.MAX_VALUE?-1:ret;
        System.out.println(ret);
    }
}